/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.domain;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author daniel.camacho.rodriguez
 */
public class UrlDomainController {

    private String bar;
    private String userPath;
    private String actualPath;

    private String root; 
    private String languages; 
    private String security; 
    private String config; 
    private String res; 

    public UrlDomainController(){
        bar  = System.getProperty("file.separator");
        userPath  = System.getProperty("user.home");
        actualPath  = System.getProperty("user.dir");
        
        root = userPath+bar+"Nominalizator";
        languages = root+bar+"Languages";
        security = root+bar+"Security";
        config = root+bar+"Config";
        res = root+bar+"Res";
        
        System.out.println(res);
    }

    public boolean isFirst(){
        File dir = new File(root);
        if(dir.exists())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public void copyFile (String s, String d) throws FileNotFoundException, IOException{
        File source = new File(s);
        File dest = new File(d);
        
        InputStream in = new FileInputStream(source);
        OutputStream out = new FileOutputStream(dest);
        
        byte[] buffer = new byte[1024];
        int len;
        while ( (len = in.read(buffer)) > 0 ) {
            out.write(buffer, 0, len);
        }
        
        in.close();
        out.close();
    }
    
    public void createFolders() throws FileNotFoundException, IOException{
        File dir = new File(languages);
        dir.mkdirs();

        dir = new File(security);
        dir.mkdirs();

        dir = new File(config);
        dir.mkdirs();
        //Copiar arxius
        // el que digi en Genis
        copyFile(actualPath+bar+"settings", getConfig()+"settings");
        copyFile(actualPath+bar+"defaults", getConfig()+"defaults");
        copyFile(actualPath+bar+"checks", getConfig()+"checks");
        
        dir = new File(res);
        dir.mkdirs();
        //copiar arxius
        // logos i 3 htmls
    }

    public String getRoot(){
        return root+bar;
    }

    public String getLanguages(){
        return languages+bar;
    }

    public String getSecurity(){
        return security+bar;
    }

    public String getConfig(){
        return config+bar;
    }

    public String gotRes(){
        return res+bar;
    }
    /*
    public String getRes(){
        String a = new String();
        a = res+bar;
        return a;
    }*/
}
